package com.yun.zf.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.zf.admin.mapper.ZfDeptCommunityMapper;
import com.yun.zf.admin.service.ZfDeptCommunityService;
import com.yun.zf.common.admin.domain.ZfDeptCommunity;
import com.yun.zf.common.admin.dto.community.AgentInfoDto;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 三级门店与小区关系表 服务实现类
 * </p>
 *
 * @author cj
 * @since 2021-05-26
 */
@Service
public class ZfDeptCommunityServiceImpl extends ServiceImpl<ZfDeptCommunityMapper, ZfDeptCommunity> implements ZfDeptCommunityService {

    @Override
    public List<Long> getCommunitys(Long deptId) {
        QueryWrapper<ZfDeptCommunity> deptCommunityQueryWrapper = new QueryWrapper<>();
        deptCommunityQueryWrapper.lambda().eq(ZfDeptCommunity::getDept3Id,deptId);
       List<ZfDeptCommunity> deptCommunityList = baseMapper.selectList(deptCommunityQueryWrapper);

      List<Long> communityIds = deptCommunityList.stream().map(c -> c.getCommunityId()).collect(Collectors.toList());
        return communityIds ;
    }

    @Override
    public int addDeptCommunity(ZfDeptCommunity deptCommunity) {
        return baseMapper.insert(deptCommunity);
    }

    @Override
    public List<AgentInfoDto> getAgentInfo(Long communityId) {
        return baseMapper.getInfo(communityId);
    }
}
